/**********************************************************************
 *                                                                    *
 * tgt - Tiny Graphics Toolbox                                        *
 *                                                                    *
 * Copyright (C) 2006-2008 Visualization and Computer Graphics Group, *
 * Department of Computer Science, University of Muenster, Germany.   *
 * <http://viscg.uni-muenster.de>                                     *
 *                                                                    *
 * This file is part of the tgt library. This library is free         *
 * software; you can redistribute it and/or modify it under the terms *
 * of the GNU Lesser General Public License version 2.1 as published  *
 * by the Free Software Foundation.                                   *
 *                                                                    *
 * This library is distributed in the hope that it will be useful,    *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU Lesser General Public License for more details.                *
 *                                                                    *
 * You should have received a copy of the GNU Lesser General Public   *
 * License in the file "LICENSE.txt" along with this library.         *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

#include "tgt/init.h"
#include "tgt/logmanager.h"

using namespace tgt;

class Tata {
public:
    Tata() {};

    void foo(){
        LDEBUG("This is a debug message");
        LINFO("This is an info message");
        LWARNING("This is a warning message");
        LERROR("This is an error message");
        LFATAL("This is a fatal message");
    }

protected:
    static const std::string loggerCat_;    
};

const std::string Tata::loggerCat_("myApp.Tata");

class Toto {
public:
    Toto() {};

    void foo(){
        LDEBUG("This is a debug message");
        LINFO("This is an info message");
        LWARNING("This is a warning message");
        LERROR("This is an error message");
        LFATAL("This is a fatal message");
    }

protected:
    static const std::string loggerCat_;    
};

const std::string Toto::loggerCat_("myApp.Toto");



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

int main(int argc, char** argv) {
    std::cout << "tgt Sample Program: logging" << std::endl << std::endl
              << "Creates some log output, written to console and file \"log.html\"." << std::endl << std::endl;
    
    tgt::init();

    // Our classes from above
    Tata tata;
    Toto toto;

    // Create a html file logging all children from every source (for example to log tgt
    // messages as well) with date, timestamp, category and LogLevel
    HtmlLog* htmlLog = new HtmlLog("log.html", true, true, true, true);
    htmlLog->addCat("", true, Debug);
    
    // Create standard console log listening only to log messages from myApp.toto with log
    // level INFO. There can be only one ConsoleLog, so this one will replace the old one.
    ConsoleLog* consoleLog1 = new ConsoleLog();
    consoleLog1->addCat("myApp.Toto", false, Info);

    // Adding loggers to the tgt::LogManager Singleton LogMgr.
    // The LogManager will take care of deleting them later.
    LogMgr.addLog(htmlLog);
    LogMgr.addLog(consoleLog1);

    toto.foo();
    
    // Get the current console logger and add a logging category.
    ConsoleLog* consoleLog2 = LogMgr.getConsoleLog();
    consoleLog2->addCat("myApp.Tata", false, Error);
    
    tata.foo();

    return 0;
}
